package iofile;

import java.io.FileWriter;
import java.io.IOException;

public class FileWriter_ {

    public static void main(String[] args) {

    }

    public void writer(){
        String filePath = "";
        FileWriter fileWriter = null;
        char[] chars = {'a','b','c'};

        try {
            //创建FiLeWriter对象，参数传入文件路径，默认为覆盖原文件，如果传入参数为(String path,true)则为在原文件末尾追加
            fileWriter = new FileWriter(filePath);
            //写入单个字符
            fileWriter.write('H');
            //写入字符数组
            fileWriter.write(chars);
            //写入数组的指定部分
            fileWriter.write("asdac".toCharArray(),0,3);
            //写入整个字符串
            fileWriter.write("asdfasf");

        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            try {
                fileWriter.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
